local hx__longxiao = fk.CreateSkill{
    name = "hx__longxiao",

    tags = {Skill.Limited},
}

hx__longxiao:addEffect("active",{
    prompt = "#hx__longxiao__prompt",
    can_use = function (self, player)
        return player:usedSkillTimes(hx__longxiao.name,Player.HistoryGame) == 0
    end,
    interaction = function (self, player)
        local all_choices = {"hx__longxiao__mabi","hx__longxiao__shixiao"}
        local choices = table.simpleClone(all_choices)
        return UI.ComboBox{choices = choices,all_choices = all_choices ,detailed = false }
    end,
    card_num = 0,
    card_filter = Util.FalseFunc,
    min_target_num = 0,
    max_target_num = 1,
    target_filter = function (self, player, to_select, selected, selected_cards)
        if not self.interaction.data then return end
        if self.interaction.data == "hx__longxiao__mabi" then
            return false
        else
            return #selected == 0 and to_select ~= player
        end
    end,
    on_use = function (self, room, effect)
        local player = effect.from
        if self.interaction.data then
            if self.interaction.data == "hx__longxiao__mabi" then
                local targets = room:getOtherPlayers(player)
                if #targets == 0 then return end
                targets = table.random(targets,math.min(#targets,2))
                for _, v in ipairs(targets) do
                    room:setPlayerMark(v,"@hx_longxiao_mabi",1)
                end
            elseif self.interaction.data == "hx__longxiao__shixiao" and #effect.tos > 0 then
                local target = effect.tos[1]
                for i, v in ipairs(target:getAllSkills()) do
                    if i <= 2 then
                        room:addTableMark(target,"@hx_longxiao_shixiao",v.name)
                        room:invalidateSkill(target,v.name,nil,hx__longxiao.name)
                    end
                end
            end
        end
    end,
})

hx__longxiao:addEffect(fk.RoundStart,{
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(hx__longxiao.name) and player:usedSkillTimes(hx__longxiao.name,Player.HistoryGame) == 0
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local suc,_ = room:askToUseActiveSkill(player,{skill_name = hx__longxiao.name, cancelable = true, prompt = "#hx__longxiao__evoke"})
        if suc then
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        player:setSkillUseHistory(hx__longxiao.name,1,Player.HistoryGame)
    end,
})

hx__longxiao:addEffect(fk.TurnStart,{
    can_refresh = function (self, event, target, player, data)
        return player:hasSkill(hx__longxiao.name,true,false) and target and target == player and player:usedSkillTimes(hx__longxiao.name,Player.HistoryGame) > 0
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room.alive_players,function (p)
            return p:getMark("@hx_longxiao_mabi") > 0 or #p:getTableMark("@hx_longxiao_shixiao") > 0
        end)
        for _, v in ipairs(targets) do
            room:setPlayerMark(v,"@hx_longxiao_mabi",0)
            for _, s in ipairs(v:getTableMark("@hx_longxiao_shixiao")) do
                room:validateSkill(v,s,nil,hx__longxiao.name)
            end
            room:setPlayerMark(v,"@hx_longxiao_shixiao",0)
        end
    end,
})

hx__longxiao:addEffect("prohibit",{
    prohibit_use = function (self, player, card)
        return player:getMark("@hx_longxiao_mabi") > 0
    end,
    prohibit_response = function (self, player, card)
        return player:getMark("@hx_longxiao_mabi") > 0
    end,
})

return hx__longxiao